<style lang="scss">
  @import 'index';
</style>

<template>
  <div class="ga-container">
    <div class="ga-tickets">

      <div class="item" v-for="(item,index) in ticketslist" :key="index" :class="{'fail':item.cc==false}" @click="getcoupon(item.coupon_id,item.cc)">
        <div class="box1">
          <p class="p1">
            ¥
            <span>{{item.coupon_amount}}</span>
          </p>
          <p class="p2">{{item.enable_amount>0?'单笔订单满'+item.enable_amount+'元':'无门槛使用'}}</p>
        </div>
        <div class="box2">
          <p class="p1">{{item.coupon_name}}</p>
          <p class="p2">{{item.coupon_starttime}}至{{item.coupon_endtime}}</p>
        </div>
      </div>

      <a href="/pages/rule/main" class="rule-box">
        <i class="gaIcon wh"></i>
        <span>优惠券说明</span>
      </a>

    </div>
  </div>
</template>

<script>
import {isLogin} from '@/utils/handleLogin'
export default {

  data () {
    return {
       ticketslist: [],
       buttonset: true,
    }
  },
  onShow () {
     isLogin(() => {
         this.load()
     })
  },
  methods: {
    /*异步加载数据*/
     async load () {
      this.buttonset = true
      this.$_util.ajax.get('https://guo-a.com/mapi/ticket/couponlist?token=' + this.$store.state.Token).then((res) => {
        if(res.code === 200){
          this.ticketslist = res.data
        }
      })
     },
     /*点击领取优惠券*/
     async getcoupon(id,isSet){
      if(!isSet || !this.buttonset){
         return false
      }
      this.buttonset = false
      this.$_util.ajax.post('https://guo-a.com/mapi/Ticket/getcoupon?token=' + this.$store.state.Token,{
        id:id
      }).then((res) => {
        if(res.code === 200){
          let that=this
          wx.showToast({
              title: '领取成功',
              icon: 'succes',
              duration: 1000,
              mask:true,
              complete:function(res){
                setTimeout(function(){
                  that.load()
                },500)
              }
          })
        }
      })
     }
  }
  
}
</script>
